REQUESTNOTIFY TEXT '"'BBSREAD.LASTERROR'"' BT '"_Ok"'
signal exit
end
if(BBSDATA.USERNAME = '') then
do
GETGLOBALDATA stem GLOBALDATA
if(rc ~= 0) then
do
address(thorport)
REQUESTNOTIFY TEXT '"'BBSREAD.LASTERROR'"' BT '"_Ok"'
signal exit
end
if(GLOBALDATA.USERNAME = '') then signal exit
else username = GLOBALDATA.USERNAME
end
else username = BBSDATA.USERNAME
if(newgame) then whiteplayer = username
select
when(username = blackplayer) then
do
color = 'Black'
othercolor = 'White'
end
when(username = whiteplayer) then
do
color = 'White'
othercolor = 'Black'
end
otherwise signal exit
end
/* ask user to specify move */
exchangepawn = 0
longcastle = 0
shortcastle = 0
passant = 0
address(thorport)
REQUESTSTRING TITLE '"ChessMaster3000"' BODY '"' || color || ' player enter your move\non the form ''xyxy''.' || '"' BT '"_Ok|_Special move|_Cancel"' MAXCHARS 4
when(fromxpos > 8 | fromxpos < 1) then errormsg = 'FROM x-coordinate out of range.'
when(fromypos > 8 | fromypos < 1) then errormsg = 'FROM y-coordinate out of range.'
when(toxpos > 8 | toxpos < 1) then errormsg = 'TO x-coordinate out of range.'
when(toypos > 8 | toypos < 1) then errormsg = 'TO y-coordinate out of range.'
when(pos.fromxpos.fromypos = ' ') then errormsg = 'Invalid FROM coordinates, no chess piece found.'
when(left(strip(pos.fromxpos.fromypos, B), 1) = '#' & color = 'White' | left(strip(pos.fromxpos.fromypos, B), 1) ~= '#' & color = 'Black') then errormsg = 'Invalid FROM coordinates, trying to\nmove other player''s chess piece.'
when(pos.toxpos.toypos ~= ' ' & left(strip(pos.toxpos.toypos, B), 1) ~= '#' & color = 'White' | left(strip(pos.toxpos.toypos, B), 1) = '#' & color = 'Black') then errormsg = 'TO square is occupied by your own piece.'
otherwise errormsg = ''
end
if(errormsg ~= '') then
do
address(thorport)
REQUESTNOTIFY TEXT '"'errormsg'"' BT '"_Ok"'
signal exit
end
/* determine whether an enemy piece has been beaten */
frompiece = compress(pos.fromxpos.fromypos, '# ')
topiece = compress(pos.toxpos.toypos, '# ')
if(pos.toxpos.toypos ~= ' ') then
do
if(topiece = 'K') then
do
address(thorport)
do 50; BEEP; end
REQUESTNOTIFY TEXT '"You have won the game!"' BT '"H_ooya!"'
/* gotta post a fancy message here */
signal exit
end
if(color = 'Black') then whitelosses = whitelosses || ', ' || strip(pos.toxpos.toypos, B)
else blacklosses = blacklosses || ', ' || strip(pos.toxpos.toypos, B)
select
when(left(blacklosses, 1) = ',') then blacklosses = substr(blacklosses, 3)
when(left(whitelosses, 1) = ',') then whitelosses = substr(whitelosses, 3)
otherwise nop
end
end
else anyonebeaten = 'FALSE'
/* move the piece to the TO square and clear the FROM square */
pos.toxpos.toypos = pos.fromxpos.fromypos
pos.fromxpos.fromypos = ' '
end
else /* special move */
do
address(thorport)
REQUESTNOTIFY TEXT '"Select special move:"' BT '"_Exchange Pawn|C_astle|_Passant|_Cancel"'
if(rc ~= 0) then signal exit
select
when(result = 0) then signal exit /* Cancel */
when(result = 1) then /* Exchange Pawn */
do
exchangepawn = 1
if(color = 'Black') then y = 1
else y = 8
availpawn.count = 0
do x=1 to 8
if(compress(pos.x.y, '# ') = 'P') then
do
availpawn.count = availpawn.count+1
k = availpawn.count
availpawn.k = translate(x, 'ABCDEFGH', '12345678') || y
end
end
if(availpawn.count = 0) then
do
address(thorport)
REQUESTNOTIFY TEXT '"No Pawn-exchanging is possible."' BT '"_Ok"'
signal exit
end
if(availpawn.count ~= 1) then
do
/* change to REQUESTNOTIFY !? */
address(thorport)
REQUESTLIST TITLE '"Choose one set of coordinates"' instem availpawn SIZEGADGET
if(rc ~= 0) then signal exit
pawncoord = result
end
else pawncoord = availpawn.1
address(thorport)
REQUESTNOTIFY TEXT '"Select new chess piece:"' BT '"_Queen|_Bishop|K_night|_Castle"'